{% extends "miramar/base.html" %}
{% load i18n %}
{% load miramar_tags %}

{% block title %}{% trans "Update page" %}{% endblock %}
{% block content_title %}<h1>{% trans "Update page" %}</h1>{% endblock %}
{% block extrahead %}
{{ form.media }}
<script type="text/javascript">
$(document).ready(function() {
  $(".version-tag").hide();
  $(".version-tag.active").slideDown('normal');
});
</script>
<style type="text/css">
#simplemodal-overlay {
  background-color:#000000;  
  opacity:0.5;  
  filter:alpha(opacity=50);  
  -moz-opacity:0.5;
}
</style>
{% endblock %}
  
{% block content %}
<form action="." method="post">
<table class="module">
  <caption>{% trans "Update page" %}</caption>
  <tr>
  	<th>{% trans "URL stub" %}</th>
  	<td><strong>{{ page.slug|escape }}</strong>
  	(<a href="{% url miramar_page_rename page.slug %}">rename</a>)
  	</td>
  </tr>
  {{ form.as_table }}
</table>
<div class="formaction"><input type="submit" /></div>
</form>
<hr />

{% for version in page.pageversion_set.all %}
  {% ifchanged version.version_tag %}
    {% if not forloop.first %}
    </tbody>
    </table>
    {% endif %}
    <script type="text/javascript">
      $(document).ready(function() {
        $("#id_h2_{{ version.version_tag }} a").click(
          function() {
            if (!$("#id_vtg_{{ version.version_tag }}").is(':visible')) {
              $(".version-tag:visible").slideUp('normal');
              $("#id_vtg_{{ version.version_tag }}").slideDown('normal');
              return false;
            }
          }
        );
      });
    </script>
    <h2 id="id_h2_{{ version.version_tag }}"><a href="#">{{ version.version_tag }}</a></h2>
    {% ifequal version.version_tag page.published_version.version_tag %}
    <table id="id_vtg_{{ version.version_tag }}" 
           class="version-tag active">
    {% else %}
    	{% if forloop.first and not page.published_version %}
        <table id="id_vtg_{{ version.version_tag }}" 
               class="version-tag active">
        {% else %}
        <table id="id_vtg_{{ version.version_tag }}"
               class="version-tag">
        {% endif %}
    {% endifequal %}
	<thead>
	  <tr>
	    <td colspan="7">
	      {% if user|has_perm:"miramar.can_revise_pageversion" %}
		      <input id="id_edit_{{ version.version_tag }}" type="button" value="{% blocktrans with version.revision as revision %}Edit revision {{ revision }}{% endblocktrans %}" />
		      <script type="text/javascript">
		        $("#id_edit_{{ version.version_tag }}").click(function() {
		          location.href="{% url miramar_pageversion_update page.slug version.version_tag %}";
		        });
		      </script>
	      {% endif %}
	    </tr>
	  </tr>
	  <tr>
	  	<th>{% trans "Revision ID" %}</th>
	  	<th>{% trans "Timestamp" %}</th>
	  	<th>{% trans "Author" %}</th>
	  	<th>{% trans "Comment" %}</th>
	  	<th>{% trans "Branch here" %}</th>
	  	<th>{% trans "Compare" %}</th>
	  	<th>{% trans "Approved?" %}</th>
	  	<th>{% trans "Published?" %}</th>
	  </tr>
	</thead>
	<tbody>
  {% endifchanged %}
  <tr{% if version.published %} class="published"{% endif %}>
    <td><a href="{% url miramar_page_detail_with_revision page.slug version.version_tag version.revision %}">
    {{ version.revision }}</a></td>
    <td>{{ version.time_stamp|date:'N j, Y P' }}</td>
    <td>{{ version.author.username }}</td>
    <td>{{ version.comment }}</td>
    <td>
      {% if user|has_perm:"miramar.can_branch_pageversion" %}
        <input id="id_branch_{{ version.id }}" type="button" value="{% trans "Branch here" %}" />
        <script type="text/javascript">
          $("#id_branch_{{ version.id }}").click(function() {
            $.modal('<iframe src="{% url miramar_pageversion_branch page.slug version.version_tag version.revision %}" height="400" width="500" style="border: 0">', {
              containerCss: {
			    height: 400,
  			    width: 500,
	  		    padding: 0
		 	  },
			  focus: true,
			  overlayClose: true,
			  onClose: function(){ window.location.reload(); }
		    });
		  });
	    </script>
      {% endif %}
    </td>
    <td>
      <input id="id_compare_{{ version.id }}" type="button" value="{% trans "Compare" %}" />
      <script type="text/javascript">
        $("#id_compare_{{ version.id }}").click(function() {
          $.modal('<iframe src="{% url miramar_pageversion_diff_form page.slug version.version_tag  version.revision %}" height="400" width="500" style="border: 0">', {
            containerCss: {
			  height: 400,
  	 	      width: 500,
	  		  padding: 0
		 	},
			focus: true,
			overlayClose: true,
		  });
		});
	  </script>
	</td>   
    <td>{% if version.approved %}
      <img src="{{ MEDIA_URL }}img/miramar/approved.png" alt="{% trans "Approved" %}" />
      {% else %}
	      {% if user|has_perm:"miramar.can_approve_pageversion" %}
	      <input id="id_approve_{{ version.id }}" type="button" value="{% trans "Approve" %}" />
	      <script type="text/javascript">
	        $("#id_approve_{{ version.id }}").click(function() {
	          $.modal('<iframe src="{% url miramar_pageversion_approve page.slug version.version_tag version.revision %}" height="400" width="500" style="border: 0">', {
	            containerCss: {
				  height: 400,
				  width: 500,
				  padding: 0
				},
				focus: true,
				overlayClose: true,
				onClose: function(){ window.location.reload(); }
			  });
			});
		  </script>
		  {% endif %}
      {% endif %}
    </td>
    <td>{% if version.published %}<strong>{% trans "Published" %}</strong>
      {% else %}
        {% if version.approved and user|has_perm:"miramar.can_publish_pageversion" %}
          <input id="id_publish_{{ version.id }}" type="button" value="{% trans "Publish" %}" />
          <script type="text/javascript">
            $("#id_publish_{{ version.id }}").click(function(){
	          $.modal('<iframe src="{% url miramar_pageversion_publish page.slug version.version_tag version.revision %}" height="400" width="500" style="border: 0">', {
	            containerCss: {
				  height: 400,
				  width: 500,
				  padding: 0
				},
				focus: true,
				overlayClose: true,
				onClose: function(){ window.location.reload(); }
			  });
            });
          </script>
        {% endif %}
      {% endif %}
    </td>
  </tr>
{% endfor %}
</tbody>
</table>  
        
{% endblock %}